package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.entity.Comments;
import com.ktjiaoyu.entity.GoodsInfo;
import com.ktjiaoyu.mapper.CommentsMapper;
import com.ktjiaoyu.service.CommentsService;
import com.ktjiaoyu.utils.Constants;
import com.ktjiaoyu.utils.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CommentsServiceImpl implements CommentsService {
    private static final Logger LOGGER= LoggerFactory.getLogger(CommentsServiceImpl.class);


    @Autowired
    private CommentsMapper commentsMapper;

    @Override
    public Page<Comments> getPage(Comments entity, Integer offset, Integer pageSize) {
        Page<Comments> page=null;
        try{
            page=new Page<Comments>();
            page.setPageSize(pageSize);
            Long count= commentsMapper.count(entity);
            page.setTotalCount(count.intValue());
            page.setPageNo(offset);

            List<Comments> data=commentsMapper.getPage(entity,page.offset(),page.getPageSize());

            page.setData(data);
        }catch (Exception e){
            LOGGER.error("GoodsInfoServiceImpl.findPage(GoodsInfo,Integer,Integer)方法出现异常。",e);
            throw e;
        }
        return page;
    }

    @Override
    public Long count(Comments entity) {
        try {
            return commentsMapper.count(entity);

        } catch (Exception e) {
            LOGGER.error("StorageRecordServiceImpl.count()方法异常.", e);
            throw e;
        }
    }

    @Override
    public int deleteById(Long id) {
        try {
            return commentsMapper.deleteById(id);

        } catch (Exception e) {
            LOGGER.error("StorageRecordServiceImpl.count()方法异常.", e);
            throw e;
        }
    }

    @Override
    public int updateStatus(Long id, Long status) {
        try {
            return commentsMapper.updateStatus(id,status);

        } catch (Exception e) {
            LOGGER.error("StorageRecordServiceImpl.count()方法异常.", e);
            throw e;
        }
    }

    @Override
    public boolean updateReply(Comments comments) {
        try {
            int count=commentsMapper.updateReply(comments);
            System.out.println(comments.getId());
            return count>0;

        } catch (Exception e) {
            LOGGER.error("StorageRecordServiceImpl.count()方法异常.", e);
            throw e;
        }
    }
}
